#include<iostream>
#include<opencv2/imgcodecs.hpp>
#include<opencv2/highgui.hpp>
#include<opencv2/imgproc.hpp>
#include<opencv2/objdetect.hpp>
#include<string>
#include<vector>

using namespace std;
using namespace cv;

int main()
{
    VideoCapture cap(0);
    Mat img;

    CascadeClassifier faceCasade;
    faceCasade.load("/home/wuyou/桌面/task/face/haarcascade_frontalface_default.xml");

    if(faceCasade.empty())
    {
        cout<<"XML file not load"<<endl;
    }

    vector<Rect> faces;

    while(true)
    {
        cap.read(img);

        faceCasade.detectMultiScale(img,faces,1.1,10);

        for(int i=0;i<faces.size();i++)
        {
            Mat imgCrop=img(faces[i]);
            imshow(to_string(i),imgCrop);
            imwrite("/home/wuyou/桌面/task/face"+to_string(i)+".jpg",imgCrop);
            rectangle(img,faces[i].tl(),faces[i].br(),Scalar(255,0,255),3);
        }

        imshow("Image",img);
        waitKey(1);

    }

    return 0;
}